<!--
 * @Description: Ajax
 * @Author: rendc
 * @Date: 2021-09-09 11:22:59
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-09 11:34:21
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Ajax</title>
</head>

<body>

</body>
<script>
  // 创建一个http请求对象 xhr - 小黄人
  var httpRequest = new XMLHttpRequest();
  // 打开一个http连接
  httpRequest.open('get', 'http://203.195.246.58:8888/index/category/findAll');
  // 发起请求
  httpRequest.send();
  // 处理响应
  httpRequest.onreadystatechange = function () {
    // httpRequest.readyState === 4 代表http请求完成
    // httpRequest.status === 200 代表请求成功了
    if (httpRequest.readyState === 4 && httpRequest.status === 200) {
      // 获取响应里的数据
      console.log(httpRequest.responseText);
    }
    if (httpRequest.readyState === 4 && httpRequest.status === 500) {
      // 获取响应里的数据
      console.log("错误" + httpRequest.responseText);
    }
  }
</script>

</html>